#include "Airport.h"

Airport::Airport()
{

}

Airport::Airport(std::istringstream& airports_file)
{
	std::string latitude0, latitude1;
	std::string longitude0, longitude1;

	getline(airports_file, _id, ',');
	getline(airports_file, _name, ',');
	getline(airports_file, _suf, ',');
	getline(airports_file, latitude0, ',');
	getline(airports_file, latitude1, ',');
	getline(airports_file, longitude0, ',');
	getline(airports_file, longitude1, '\n');

	_latitude = util::string_to_double(latitude0) + (util::string_to_double(latitude1) / 60.0);
	_longitude = util::string_to_double(longitude0) + (util::string_to_double(longitude1) / 60.0);

	_localFlights = 0;
	_localHours = 0;
	_xcFlights = 0;
	_xcHours = 0;
	_firstDate = "0";
	_localFirstDate = "0";
}

Airport::~Airport()
{

}

std::string Airport::logLine() const
{
	return _logLine;
}

std::string Airport::name() const
{
	return _name;
}

std::string Airport::suf() const
{
	return _suf;
}

std::string Airport::id() const
{
	return _id;
}

double Airport::latitude() const
{
	return _latitude;
}

double Airport::longitude() const
{
	return _longitude;
}

double Airport::localFlights() const
{
	return _localFlights;
}

double Airport::localHours() const
{
	return _localHours;
}

double Airport::xcFlights() const
{
	return _xcFlights;
}

double Airport::xcHours() const
{
	return _xcHours;
}

std::string Airport::firstDate() const
{
	return _firstDate;
}

std::string Airport::lastDate() const
{
	return _lastDate;
}

std::string Airport::localFirstDate() const
{
	return _localFirstDate;
}

std::string Airport::localLastDate() const
{
	return _localLastDate;
}

//void Airport::setAirport(std::string logLine, std::string id, std::string name, std::string suf, double latitude, double longitude)
//{
//	_logLine = logLine;
//	_id = id;
//	_name = name;
//	_suf = suf;
//	_latitude = latitude;
//	_longitude = longitude;
//	_localFlights = 0;
//	_localHours = 0;
//	_xcFlights = 0;
//	_xcHours = 0;
//	_firstDate = "0";
//	_localFirstDate = "0";
//}

void Airport::addLocal(std::string Date, double newLocalHours)
{
	if (_localFirstDate == "0")
		_localFirstDate = Date;
	if (_firstDate == "0")
		_firstDate = Date;
	++_localFlights;
	_localHours += newLocalHours;
	_localLastDate = Date;
	_lastDate = Date;
}


void Airport::addXc(std::string Date, double newXcHours)
{
	if (_firstDate == "0")
		_firstDate = Date;
	++_xcFlights;
	_xcHours += newXcHours;
	_lastDate = Date;
}